package com.libl.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.libl.mapper.DtsGoodsSpecificationMapper;
import com.libl.pojo.DtsGoodsSpecification;
import com.libl.service.DtsGoodsSpecificationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class DtsGoodsSpecificationServiceImpl implements DtsGoodsSpecificationService {
    @Autowired
    DtsGoodsSpecificationMapper specificationMapper;

    @Override
    public List<DtsGoodsSpecification> findAttributesByGoodsId(Integer id) {
        LambdaQueryWrapper<DtsGoodsSpecification> wrapper= new LambdaQueryWrapper<>();

        wrapper.eq(DtsGoodsSpecification::getGoodsId, id);
        wrapper.eq(DtsGoodsSpecification::getDeleted, false);

        List<DtsGoodsSpecification> attributeList = specificationMapper.selectList(wrapper);

        return attributeList;
    }

    @Override
    public void deleteByGoodsId(Integer id) {
        LambdaQueryWrapper<DtsGoodsSpecification> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(DtsGoodsSpecification::getGoodsId, id);

        specificationMapper.delete(wrapper);
    }

    @Override
    public void insert(DtsGoodsSpecification specification) {
        specification.setAddTime(new Date());
        specification.setUpdateTime(new Date());
        specification.setDeleted(false);

        specificationMapper.insert(specification);
    }

    @Override
    public void updateByGoodsId(Integer id) {
        LambdaUpdateWrapper<DtsGoodsSpecification> wrapper = new LambdaUpdateWrapper();
        wrapper.eq(DtsGoodsSpecification::getGoodsId,id);

        DtsGoodsSpecification specification = new DtsGoodsSpecification();
        specification.setDeleted(true);

        specificationMapper.update(specification,wrapper);
    }
}
